// Organism.cpp
#include <cstdlib>
#include "Organism.hpp"

Organism::Organism(const std::string& n, double rProb, int max)
{
  name = n;
  reproProb = rProb;
  maxAge = max;
  age = 0;
}

int Organism::advance()
{
  // if we're too old, die:
  if(age == maxAge)
    return -1;
	
  // otherwise we're one year older
  age ++;

  // figure out if we reproduce

  // get a double between 0 and 1, make sure to avoid integer divition:
  double randNum = rand() / (static_cast<double>(RAND_MAX));

  if (randNum < reproProb) {
    return 1;
  }
}

Organism::Organism(const Organism& org)
{
  name = org.name;
  reproProb = org.reproProb;
  maxAge = org.maxAge;
  age = 0;
}
